﻿#include <sb.h>

#define MAXREP		10
#define MAXVCV		10

void foreach_int_int(int key, int value)
{
	k_printf("%d -> %d\n", key, value);
}

int main()
{
	k_mesg("TPL CONTAINERS TEST\n");

	double ts = k_curtick();

	for (int rep = 0; rep < MAXREP; rep++)
	{
		k_mesgf("REP %d START\n\n", rep);

		// 시퀸스 배열
		tpl::SeqArray<int>* sa = new tpl::SeqArray<int>();
		for (int i = 0; i < MAXVCV; i++) sa->Add(i);

		for (auto it = sa->ConstBegin(); it != sa->ConstEnd(); ++it)
			k_printf("-> %d\n", *it);

		delete sa;

		// 벡터 배열
		tpl::VecArray<float>* va = new tpl::VecArray<float>();
		for (int i = 0; i < MAXVCV; i++) va->Add((float)i);

		for (auto it = va->ConstBegin(); it != va->ConstEnd(); ++it)
			k_printf("-> %f\n", *it);

		delete va;

		// 슬라이스
		tpl::SliceArray<int>* fs = new tpl::SliceArray<int>(5);
		for (int i = 0; i < MAXVCV; i++) fs->Push(i * 10);

		for (auto it = fs->ConstBegin(); it != fs->ConstEnd(); ++it)
			k_printf("-> %d\n", *it);

		delete fs;

		// 리스트
		tpl::LinkedList<float>* ll = new tpl::LinkedList<float>();
		for (int i = 0; i < MAXVCV; i++) ll->Append((float)i*1.1f);

		for (auto it = ll->ConstBegin(); it != ll->ConstEnd(); ++it)
			k_printf("-> %f\n", *it);

		delete ll;

		// 솔로
		tpl::SoloList<int>* sl = new tpl::SoloList<int>();
		for (int i = 0; i < MAXVCV; i++) sl->Append(i + 5);

		for (auto it = sl->ConstBegin(); it; ++it)
			k_printf("-> %d\n", *it);

		delete sl;

		// 해시
		tpl::HashTable<int, int>* ht = new tpl::HashTable<int, int>();
		for (int i = 0; i < MAXVCV; i++) ht->Set(i, i * 100);

		for (auto it = ht->ConstBegin(); it != ht->ConstEnd(); ++it)
			k_printf("%d -> %d\n", it->key, it->map);

		delete ht;

		// 묶음
		tpl::Mukum<int, int>* mk = new tpl::Mukum<int, int>();
		for (int i = 0; i < MAXVCV; i++) mk->Set(i, i * 100);

		mk->LoopEach(&foreach_int_int);

		delete mk;

		// 스뜨림
		tpl::String* ss = new tpl::String("1234");

		if (*ss == "1234")
			k_printf("OK!!!\n");

		*ss += "ABC";

		k_printf("%s\n", ss->ConstData());

		delete ss;

		k_mesgf("REP %d END\n\n", rep);
		k_mesgf("%u / %u\n", (kuint)k_heapsize(), (kuint)k_heapmax());
		k_sleep(100);
	}

	k_mesgf("TICK: %.5f\n", k_curtick() - ts);
	k_mesgf("%u / %u\n", (kuint)k_heapsize(), (kuint)k_heapmax());
}
